package com.jp.knowledge.view;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by 528787067@qq.com on 2017/3/13.
 */

public class DrawerBehavior extends CoordinatorLayout.Behavior<View> {
    private int mStartY;

    public DrawerBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
        return true;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        if (mStartY==0)
            mStartY = (int) dependency.getY();
        float percent = dependency.getY()/mStartY;
        child.setY(child.getHeight()*(1-percent) - child.getHeight());
        return true;
    }
}
